<?php

namespace App\Modules\Manage\Model;

//use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
//use Cache;

class UserModel extends Model
{
    protected $table = 'pig_user';
    protected $fillable = ['id','mobile','openid','nickname','update_time'];
    //public  $timestamps = true;


    static function login($msg)
    {

        $result = self::where('mobile',$msg)->first();

        if ($result) {
            //若存在则直接返回用户信息
            $result = $result->toArray();
            return $result;
        } else {
            $data = [];
            $data['mobile'] = $msg;
            $data['nickname'] = md5(uniqid());
            $data['update_time'] = time();
//            $insertRes = self::create($data);
            $id = self::insertGetId($data);
            $data['id'] = $id;
            return $data;
        }
    }


}
